//package com.ca.demo.config;
//
//import org.apache.ibatis.session.SqlSessionFactory;
//import org.mybatis.spring.SqlSessionFactoryBean;
//import org.mybatis.spring.annotation.MapperScan;
//import org.springframework.beans.factory.annotation.Value;
//import org.springframework.boot.autoconfigure.jdbc.DataSourceBuilder;
//import org.springframework.boot.context.properties.ConfigurationProperties;
//import org.springframework.context.annotation.Bean;
//import org.springframework.context.annotation.Configuration;
//import org.springframework.context.annotation.Primary;
//import org.springframework.core.io.support.PathMatchingResourcePatternResolver;
//import org.springframework.jdbc.datasource.DataSourceTransactionManager;
//import org.springframework.transaction.annotation.EnableTransactionManagement;
//
//import javax.sql.DataSource;
//
///**
// * @Author XieLei
// * @Date 2017/6/22 9:37
// */
//@Configuration
//@EnableTransactionManagement
//@MapperScan(basePackages = "com.ca.demo.mapper.slave", sqlSessionFactoryRef = "slaveSqlSessionFactory")
//public class SlaveDataSourceConfig {
//
//    @Value("${druid.type}")
//    private Class<? extends DataSource> dataSourceType;
//
//    @Value("${mybatis.slave.mapperLocation}")
//    private String mapperLocation = "classpath:mapper/slave/*.xml";
//
//    @Bean(name = "slaveDataSource")
//    @ConfigurationProperties(prefix = "druid.slave")
//    public DataSource slaveDataSource() {
//        return DataSourceBuilder.create().type(dataSourceType).build();
//    }
//
//    @Bean(name = "slaveTransactionManager")
//    public DataSourceTransactionManager slaveTransactionManager() {
//        return new DataSourceTransactionManager(slaveDataSource());
//    }
//
//    @Bean(name = "slaveSqlSessionFactory")
//    public SqlSessionFactory slaveSqlSessionFactory() {
//        SqlSessionFactoryBean sessionFactory = new SqlSessionFactoryBean();
//        sessionFactory.setDataSource(slaveDataSource());
//
//        // TODO 分页插件
//
//        try {
//            sessionFactory.setMapperLocations(new PathMatchingResourcePatternResolver().getResources(mapperLocation));
//            return sessionFactory.getObject();
//        } catch (Exception e) {
//            e.printStackTrace();
//            throw new RuntimeException(e);
//        }
//    }
//}
